@extends('www/zc-666/layout')
@section('title',$orderInfo->real_name."的众筹")
@section('content')

    <div class="share-mobile" style="background-image:url('/{{$orderInfo->face_img}}')">

        <div class="mobile-name">
            <p class="name">{{$orderInfo->real_name}}</p>

            <p class="mobile">手机</p>
        </div>

        <div class="btns">

            <div class="jishi hide" id="jishi" data-time="0">00:01</div>

            <img src="/www/zc666/images/common/clock-message.png" class="bigimg">

            {{--外层边框--}}
            <div class="call-bg">

                {{--内层白色--}}
                <div class="call-middle" id="call-middle">
                    {{--圆--}}
                    <img class="call-cycle" id="cycle" src="/www/zc666/images/common/call.png">
                </div>

                {{--圆--}}

                <a class="call-middle hide" href="/www/zhongchou666/enter?fun=order&orderId={{$orderInfo->id}}">一探究竟</a>
            </div>
        </div>

        <audio id="video" class="hide">
            <source src="/www/zc666/mp3/{{$orderInfo->id}}.mp3" type="audio/mpeg">
        </audio>

        <audio id="ls" class="hide" autoplay>
            <source src="/www/zc666/images/common/lingsheng.mp3" type="audio/mpeg">
        </audio>

    </div>

    <script src="https://cdn.bootcss.com/touchjs/0.2.14/touch.min.js"></script>

    <script>

        window.onload = function () {

            if (typeof WeixinJSBridge == "object" && typeof WeixinJSBridge.invoke == "function") {
                WeixinJSBridge.invoke('getNetworkType', {}, function (res) {
                    var ls = document.getElementById('ls');
                    ls.play();
                });
            }

            var callbg = $('#call-middle');
            var callbgwidth = callbg.css('width');
            var delegateElement = document.getElementById('cycle');
            var canswiping = true;
            var touchconfig = {
                tap: false,                  //tap类事件开关, 默认为true
                doubleTap: false,            //doubleTap事件开关， 默认为true
                hold: false,                 //hold事件开关, 默认为true
                holdTime: 650,              //hold时间长度
                swipe: true,                //swipe事件开关
                swipeTime: 300,             //触发swipe事件的最大时长
                swipeMinDistance: 18,       //swipe移动最小距离
                swipeFactor: 1,             //加速因子, 值越大变化速率越快
                drag: false,                 //drag事件开关
                pinch: false,                //pinch类事件开关
            }

            touch.config = touchconfig;
            touch.on(delegateElement, 'swiping dragend', function (obj) {
                var type = obj.type;
                var direction = obj.direction;
                var oldWidth = parseInt(callbg.css('width'));
                if (canswiping == false) {
                    return;
                }

                if (type == 'dragend' && oldWidth > 150) {
                    callbg.css('width', callbgwidth);
                    return false;
                }

                //滑动成功
                if (oldWidth < 150) {
                    canswiping = false;
                    callbg.css('width', "80px");
                    $('#jishi').removeClass('hide')
                    document.getElementById('ls').pause();
                    var audio = document.getElementById('video');
                    //播放音乐
                    if (typeof WeixinJSBridge == "object" && typeof WeixinJSBridge.invoke == "function") {
                        WeixinJSBridge.invoke('getNetworkType', {}, function (res) {
                            audio.play();
                            var iiii = setInterval(function () {
                                if (audio.ended) {
                                    clearInterval(iiii);
                                    setTimeout(function () {
                                        location.href = $('a.call-middle').attr('href');
                                    }, 1000);
                                }
                            }, 500);
                        })
                    }

                    //隐藏菜单按钮
                    callbg.remove();
                    $('.call-middle.hide').removeClass('hide').hide().fadeIn();
                    setInterval(setTime, 1000);

                } else if (direction == 'right' && oldWidth > 100) {
                    var x = obj.distanceX / 10;
                    var newWidth = (oldWidth - x) + "px";
                    callbg.css('width', newWidth);
                }
            });


            function setTime() {
                var jishi = $('.jishi');
                var time = jishi.data('time');
                time = time + 1;
                jishi.data('time', time);
                var min = parseInt(time / 60);
                var sen = time % 60;
                var text = twodata(min) + ":" + twodata(sen);
                jishi.text(text);
            }

            function twodata(num) {
                return num < 10 ? "0" + num : num;
            }

            @if(!is_windows())

                @if($orderInfo->open_id == $userInfo['openid'])
                        var title   = "我是{{$orderInfo->real_name}}，正在参加百万大学生众筹自学习——大学生第二课堂，请大家支持我！";
                        var desc    = "快来为我打Call吧，等你来助力哦！";
                        var groupTitle = title + desc ;
                @else
                        var title   = "我的好友{{$orderInfo->real_name}}为学习众筹，圆梦发起百万大学生第二课堂社群学习计划，需要你的支持。";
                        var desc    = "邀你一起助学成才！";
                        var groupTitle = title +desc ;
                @endif

                var link    = appRoot + "www/zhongchou666/enter?fun=share_mobile&orderId={{$orderInfo->id}}";
                var imgUrl  = appRoot + "{{$orderInfo->face_img}}";

                wx.config(<?php echo $weixinJs->config(array('onMenuShareAppMessage', 'onMenuShareTimeline'), false) ?>);
                wx.ready(function(){
                    //朋友圈
                    wx.onMenuShareTimeline({
                        title: groupTitle, // 分享标题
                        link: link,
                        imgUrl: imgUrl, // 分享图标
                        success: function () {
                            // 用户确认分享后执行的回调函数

                        },
                        cancel: function () {
                            // 用户取消分享后执行的回调函数
                        }
                    });

                    //获取“分享给朋友”
                    wx.onMenuShareAppMessage({
                        title: title,
                        desc: desc,
                        link: link,
                        imgUrl: imgUrl,
                        success: function () {

                        },
                        cancel: function () {

                        }
                    });
                });
            @endif

        }
    </script>

@endsection